<!DOCTYPE html>
<html lang="zh">
<head>

    <include file="index/index_style" title="管理后台"/>
    <!--multi-select-->
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/js/jquery-multi-select/css/multi-select.css"/>
</head>
<body class="navbar-fixed">
<!-- header -->
<include file="index/header"/>
<!-- / header -->

<!-- menu -->
<include file="index/menu" publish="active"/>
<!-- / menu -->

<section id="content">
    <section class="main padder">
        <div class="clearfix">
            <h4><i class="icon-share-alt"></i>发布</h4>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <!-- .breadcrumb -->
                <ul class="breadcrumb">
                    <li><a href="#"><i class="icon-home"></i>主页</a></li>
                    <li><a href="#"><i class="icon-file-text"></i>新闻</a></li>
                    <li class="active">发布</li>
                </ul>
                <!-- / .breadcrumb -->
            </div>
            <!--action=""-->
            <div class="col-lg-12">
                <section class="panel">
                    <form id="news_form" class="form-horizontal" data-validate="parsley">
                        <div class="form-group">
                            <label class="col-lg-3 control-label">标题</label>
                            <div class="col-lg-7">
                                <input type="text" name="title" placeholder="不超过20个字"
                                       class="bg-focus form-control parsley" data-maxlength="20" data-required="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-lg-3">分类</label>
                            <div class="col-lg-4" data-resize="auto">
                                <select class="form-control parsley" name="tag">
                                    <volist name="tags" id="tag">
                                        <option value="{$tag.tid}">{$tag.name}</option>
                                    </volist>
                                </select>
                            </div>
                        </div>

                        <div class="col-lg-12 line line-dashed m-t-large"></div>

                        <div class="form-group">
                            <label class="col-lg-3 control-label">发布者</label>
                            <div class="col-lg-3">
                                <input type="text" name="publisher" placeholder="admin"
                                       class="bg-focus form-control parsley" data-maxlength="10">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-3 control-label">来源</label>
                            <div class="col-lg-7">
                                <input type="text" name="resource" placeholder="PinPaper"
                                       class="bg-focus form-control parsley" data-maxlength="20">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-3 control-label">原文地址</label>
                            <div class="col-lg-7">
                                <input type="text" name="relink" placeholder="http://pinpaper.king.moe"
                                       class="bg-focus form-control parsley" data-type="url">
                            </div>
                        </div>

                        <div class="col-lg-12 line line-dashed m-t-large"></div>

                        <div class="form-group">
                            <label class="col-lg-6 control-label">正文</label>
                        </div>
                        <div class="form-group">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                                <textarea id="news_content" name="news_content"
                                          class="form-control"></textarea>
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                        <div class="form-group">
                            <div class="col-lg-9 col-offset-5">
                                <a class="btn btn-white">取消</a>
                                <a id="submit" class="btn btn-primary">发布</a>
                            </div>
                        </div>
                    </form>

                </section>
            </div>
        </div>
    </section>
</section>

<!-- .modal -->

<div id="add-tag" class="modal fade">
    <form class="m-b-none">
        <div class="modal-dialog pos-abt" style="margin-top:-235px; top:50%">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i
                            class="icon-remove"></i></button>
                    <h4 class="modal-title" id="">添加标签</h4>
                </div>
                <div class="modal-body">
                    <div class="block">
                        <label class="control-label">名称</label>
                        <input id="tagname" name="name" type="text" class="form-control" placeholder="名称">
                    </div>

                    <!-- 提示消息 -->
                    <div class="alert alert-warning message-alert-box" style="display: none">
                        <i class="icon-bell-alt"></i><strong><span class="message-alert"></span></strong>
                    </div>

                    <div class="alert alert-success message-success-box" style="display: none">
                        <i class="icon-ok-sign icon-large"></i><strong><span class="message-success"></span></strong>
                    </div>


                </div>
                <div class="modal-footer">
                    <button id="submit" type="button" class="btn btn-small btn-primary">保存</button>
                </div>
            </div><!-- /.modal-content -->
        </div>
    </form>
</div>

<div id="add-tips" class="modal fade">
    <form class="m-b-none">
        <div class="modal-dialog pos-abt" style="margin-top:-235px; top:50%">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-hidden="true">×
                    </button>
                    <h4 class="modal-title">
                        提示
                    </h4>
                </div>
                <div class="modal-body" id="tips_content">

                </div>
            </div>
        </div><!-- /.modal-content -->
</div>
</form>
</div>
<!-- / .modal -->


<script src="__PUBLIC__/js/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="__PUBLIC__/js/bootstrap.js"></script>
<!-- app -->
<script src="__PUBLIC__/js/app.js"></script>
<script src="__PUBLIC__/js/app.plugin.js"></script>
<script src="__PUBLIC__/js/app.data.js"></script>

<!-- fuelux -->
<script src="__PUBLIC__/js/fuelux/fuelux.js"></script>
<!-- file input -->
<script src="__PUBLIC__/js/file-input/bootstrap.file-input.js"></script>
<!-- parsley -->
<script src="__PUBLIC__/js/parsley/parsley.min.js"></script>
<!-- ckeditor -->
<script src="__PUBLIC__/js/ckeditor/ckeditor.js" type="text/javascript"></script>

<!-- page script -->
<script>

    $(function () {
        // CK Editor
        CKEDITOR.replace('news_content', {
            filebrowserImageUploadUrl: "{:U('/Admin/News/addPic')}",
            toolbarGroups: [
                {name: 'clipboard', groups: ['clipboard', 'undo']},
                {name: 'links', groups: ['links']},
                {name: 'insert', groups: ['insert']},
                {name: 'forms', groups: ['forms']},
                {name: 'tools', groups: ['tools']},
                {name: 'document', groups: ['mode', 'document', 'doctools']},
                {name: 'others', groups: ['others']},
                '/',
                {name: 'basicstyles', groups: ['basicstyles', 'cleanup']},
                {name: 'paragraph', groups: ['list', 'indent', 'blocks', 'align', 'bidi', 'paragraph']},
                {name: 'styles', groups: ['styles']}
            ]
        });
    });


    $("#submit").click(function () {
        var dialog = $("#add-tips");
        var tips = $("#tips_content");

        var ok = $('#news_form').parsley('validate');
        var title = $("input[name='title']").val();
        var tag = $("select[name='tag']").val();
        var publisher = $("input[name='publisher']").val();
        var resource = $("input[name='resource']").val();
        var relink = $("input[name='relink']").val();
        var content = CKEDITOR.instances.news_content.getData();
        if (ok && content) {
            $.ajax({
                'type': 'post',
                'data': {
                    'title': title,
                    'publisher': publisher,
                    'relink': relink,
                    'resource': resource,
                    'content': content,
                    'tag': tag
                },
                'url': "{:U('/Admin/News/add')}",
                'dataType': 'json',
                success: function (data) {
                    if (data.code == '1') {
                        tips.html(data.message);
                        dialog.modal('show');
                    } else {
                        tips.html(data.message);
                        dialog.modal('show');
                    }
                },
                error: function (e) {
                    tips.html('服务器繁忙,请稍后再试');
                    dialog.modal('show');
                }
            });
        } else if (!ok) {
            return false;
        } else if (!content) {
            tips.html('请填写文章内容');
            dialog.modal('show');
        }
    })
</script>
</body>
</html>